package com.cmc.cloud.cmclink.doc.controller.admin.manifest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cmc.cloud.cmclink.doc.api.document.req.cargomanifest.CargoManifestReqDTO;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.service.manifest.CargoManifestService;
import com.cmc.cloud.cmclink.doc.vo.manifestvo.cargomanifest.CargoManifestQueryReqVO;
import com.cmc.cloud.cmclink.doc.vo.manifestvo.cargomanifest.CargoManifestQueryRespVO;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.operatelog.core.annotations.OperateLog;
import com.cmes.framework.operatelog.core.enums.OperateTypeEnum;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * CARGO MANIFEST前端接口Controller
 *
 * @author chenzheng
 */
@Tag(name = "管理后台 - CARGO MANIFEST")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/cargo/manifest")
public class CargoManifestController {
    @Resource
    private CargoManifestService cargoManifestService;

    @Operation(summary = "查询过滤条件")
    @OperateLog(type = OperateTypeEnum.GET)
    @PostMapping("/query")
    @PreAuthorize("@ss.hasPermission('doc:cargoManifest:search')")
    public CommonResult<CargoManifestQueryRespVO>
        queryCargoManifest(@Valid @RequestBody CargoManifestQueryReqVO reqVO) {
        return CommonResult.success(cargoManifestService.queryCargoManifest(reqVO));
    }

    @Operation(summary = "下载Cargo Manifest")
    @OperateLog(type = OperateTypeEnum.EXPORT)
    @PostMapping("/download")
    @Parameter(name = "type", description = "文件类型", required = true, example = "pdf, excel, word")
    @PreAuthorize("@ss.hasPermission('doc:cargoManifest:export')")
    public CommonResult<Void> downloadCargoManifest(HttpServletResponse response,
        @Valid @RequestBody CargoManifestReqDTO reqVO) {
        cargoManifestService.downloadCargoManifest(response, reqVO);
        return CommonResult.success();
    }
}
